﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;

namespace Ex4.ParsingDate
{
    class ParsingDate
    {
        private const string DATE_FORMAT_1 = "dd.mm.yyyy";
        private const string DATE_FORMAT_2 = "dd/mm/yyyy";
        private const string DATE_FORMAT_3 = "dd.mm.yy";
        private const string DATE_FORMAT_4 = "dd/mm/yy";
        
        private static string[] formats = new string[4];
            
        
        private static void ParseDate(string input)
        {
            formats[0] = DATE_FORMAT_1;
            formats[1] = DATE_FORMAT_2;
            formats[2] = DATE_FORMAT_3;
            formats[3] = DATE_FORMAT_4;

            DateTime result = default(DateTime);
            try
            {
                result = DateTime.ParseExact(input, formats, CultureInfo.InvariantCulture, DateTimeStyles.None);
                Console.WriteLine(string.Format("day={0:dd}, month={1:MM}, year={2:yyyy}", result, result, result));
            }
            catch (System.FormatException)
            {
                Console.WriteLine("Parsed string is not in the supported formats!");

                Console.WriteLine("Supported Formats are: \n{0} | {1} | {2} | {3}", 
                    DATE_FORMAT_1, DATE_FORMAT_2, DATE_FORMAT_3, DATE_FORMAT_4);
            }
        }

        static void Main(string[] args)
        {
            string date = "22.12.1991";
            ParseDate(date);
            string date2 = "12/4/1900";
            ParseDate(date2);
        }
    }
}
